﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __IMPL_DES_IMPL_H__
#define __IMPL_DES_IMPL_H__

#include "../tools/head.h"

namespace xos_encrypt
{

    class des_impl : public xos_stl::mem_item< xos::release_impl< des_impl >, thread_lock >,
		public i_des
    {
    public:
        typedef xos::release_impl< des_impl > T;

    public:
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        static int get_addr( POOL *** pppPool, LIST *** pppList );

    public:
        des_impl();
        ~des_impl();

    protected:
        int init_data();

    public:
        int init();
        int term();

    public:
        // other : 返回长度
        //    -1 : 失败
        int encode( char * lpszOutBuf, const char * lpszInBuf, int nInLen );
        int decode( char * lpszOutBuf, const char * lpszInBuf, int nInLen );

        // encode with buf
        int encode( xos_box::i_buf * pOutBuf, xos_box::i_buf * pInBuf );
        int decode( xos_box::i_buf * pOutBuf, xos_box::i_buf * pInBuf );

        // encode with list
        int encode( xos_box::i_list * pOutList, xos_box::i_list * pInList );
        int decode( xos_box::i_list * pOutList, xos_box::i_list * pInList );

        // 3des方法
        int set_3des_key( const char * lpszKey, int nKeyLen );

    private:
        xos_common::i_misc * m_pMisc;

        char m_sz3DesKey[32];
        int m_n3DesKeyLen;
    };

} // xos_encrypt

#endif // __IMPL_DES_IMPL_H__
